package com.opmsys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.opmsys.mapper.RepairMapper;
import com.opmsys.pojo.dto.RepairPageDTO;
import com.opmsys.pojo.entity.Accident;
import com.opmsys.pojo.entity.Repair;
import com.opmsys.result.PageResult;
import com.opmsys.service.AccidentService;
import com.opmsys.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述
 *
 * @datatime:2024-06-18 12:31
 */
@Service
public class RepairServiceImpl implements RepairService{

    @Autowired
    RepairMapper repairMapper;

    /**
     * 新增维修
     * @param repair
     */
    @Override
    public void add(Repair repair) {
        repairMapper.insert(repair);
    }

    /**
     * 更新维修记录
     * @param repair
     */
    @Override
    public void update(Repair repair) {
        repairMapper.update(repair);
    }

    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void delete(List<Integer> ids) {
        ids.forEach(id->{
            repairMapper.deleteById(id);
        });
    }

    /**
     * 维修记录分页查询
     * @param repairPageDTO
     * @return
     */
    @Override
    public PageResult pageQuery(RepairPageDTO repairPageDTO) {
        PageHelper.startPage(repairPageDTO.getPage(),repairPageDTO.getPageSize());
        Page<Repair> page = repairMapper.pageQuery(repairPageDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void deleteByAccidentIds(List<Integer> ids) {
        ids.forEach(id->{
            repairMapper.deleteByAccidentId(id);
        });
    }
}
